//
//  PersonCenter.m
//  YYPHSpeedJump
//
//  Created by sujiang on 15/12/21.
//  Copyright © 2015年 sujiang. All rights reserved.
//

#import "PersonCenter.h"
#import "MineHomeCell.h"
#import "PasswordViewController.h"
#import "PasswordTextField.h"
#import "SexTableViewController.h"
#import "BirthDateView.h"
#import "AddressManager.h"

@interface PersonCenter ()<UITableViewDelegate, UITableViewDataSource,UIImagePickerControllerDelegate,UINavigationControllerDelegate,UITextFieldDelegate>
{
    UIView *baseView;
    UIView *photoView;
    BirthDateView *birthDateView;
    MineHomeCell *personCell;
    
    UILabel *sexcellLable;
    UITableViewCell *cell ;
    UILabel *birthDateLable;
    UIViewController *userNameVC;
    
    
}
@property (nonatomic, strong) UIImage *ima;
@property (nonatomic, strong) NSString *token;
@property (nonatomic, strong) NSString *imageUrl;
@property (nonatomic, strong) SexTableViewController *sexTableVC;
@property (nonatomic, strong) UILabel *nameLable ;
@property (nonatomic, strong) PasswordTextField *userText;
@property (nonatomic, strong) NSString *name;

@end

@implementation PersonCenter
- (void)viewWillAppear:(BOOL)animated
{
    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self addSubViews];
    self.imageUrl = [[NSUserDefaults standardUserDefaults] objectForKey:@"headerImageUrl"];
    self.dateAndDay = [[NSUserDefaults standardUserDefaults]objectForKey:@"birthday"];
    [self.tableView registerNib:[UINib nibWithNibName:@"MineHomeCell" bundle:nil] forCellReuseIdentifier:@"MineHomeCell"];
    self.tableView.scrollEnabled = NO;
   }

- (void)requestData
{
    NSString *urlStr = [NSString stringWithFormat:@"%@%@",kBaseUrl,kUserInfoUrl];
    // NSLog(@"+++%@", self.name);
    NSDictionary *dic =@{@"u":[[NSUserDefaults standardUserDefaults]objectForKey:@"user_id"],@"nickname":self.name,@"birthday":self.dateAndDay,@"gender":[[NSUserDefaults standardUserDefaults]objectForKey:@"selectIndex"],@"head_img_url":self.imageUrl};
    [NetworkHandle getInfoWithUrl:urlStr dictionary:dic success:^(NSDictionary *dictionary) {
        if ([dictionary[@"code"] integerValue] == 200) {
             self.nameLable.text = self.name;
            [[NSUserDefaults standardUserDefaults] setObject:self.name forKey:@"userName"];
            [[NSUserDefaults standardUserDefaults] setObject:sexcellLable.text forKey:@"sexName"];
            [[NSUserDefaults standardUserDefaults] setObject:self.imageUrl forKey:@"headerImageUrl"];
            [[NSUserDefaults standardUserDefaults] setObject:birthDateLable.text forKey:@"birthday"];
            [[NSUserDefaults standardUserDefaults]setObject:UIImagePNGRepresentation(self.ima) forKey:@"headerImage1"];
            [userNameVC.navigationController popViewControllerAnimated:YES];
            dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
                [Tools showAlert:@"修改成功"];
                });
        } else {
            self.name = [[NSUserDefaults standardUserDefaults]objectForKey:@"userName"];
            [Tools showAlert:dictionary[@"message"]];
        }
       
    }];

}
- (NSMutableArray *)dataArray
{
    if (!_dataArray) {
        _dataArray = [NSMutableArray arrayWithObjects:@"", @"昵称", @"性别", @"出生日期",  @"修改密码",@"收货地址", nil];
    }
    return _dataArray;
}

- (void)addSubViews
{
    self.navigationItem.title = @"个人中心";
    self.tableView = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].bounds style:(UITableViewStyleGrouped)];
    [self.view addSubview:self.tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    
    UIView *aView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, kScreenWidth, 100)];
    self.tableView.tableFooterView = aView;
    UILabel *weLable = [[UILabel alloc]initWithFrame:CGRectMake((kScreenWidth-160)/2,kScreenHeight-200-64, 160, 30)];
    weLable.backgroundColor = [UIColor clearColor];
    weLable.text =@"联系我们";
    weLable.textColor = kColors(218, 166, 46, 1);
    weLable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:weLable];
    UIImageView *lxPhoneImg = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenWidth-200)/2+15,kScreenHeight-170-64+7, 15, 15)];
    lxPhoneImg.image = [UIImage imageNamed:@"lxdianhua"];
    [self.view addSubview:lxPhoneImg];
    UILabel *phoneLable = [[UILabel alloc]initWithFrame:CGRectMake((kScreenWidth-200)/2,kScreenHeight-170-64, 200, 30)];
    phoneLable.backgroundColor = [UIColor clearColor];
    phoneLable.text = @"010-84760633";
    phoneLable.textColor = kColors(218, 166, 46, 1);
    phoneLable.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:phoneLable];
    UIImageView *lxQQImg = [[UIImageView alloc]initWithFrame:CGRectMake((kScreenWidth-200)/2+30,kScreenHeight-140-64+7, 15, 15)];
    lxQQImg.image = [UIImage imageNamed:@"lxQQ"];
    [self.view addSubview:lxQQImg];
    UILabel *QQlabel = [[UILabel alloc]initWithFrame:CGRectMake((kScreenWidth-200)/2,kScreenHeight-140-64, 200, 30)];
    QQlabel.backgroundColor = [UIColor clearColor];
    QQlabel.text = @"417786992";
    QQlabel.textColor = kColors(218, 166, 46, 1);
    QQlabel.textAlignment = NSTextAlignmentCenter;
    [self.view addSubview:QQlabel];
    UILabel *cipherLabel = [[UILabel alloc]initWithFrame:CGRectMake(kScreenWidth-150, kScreenHeight-110-64, 150, 30)];
    cipherLabel.font =[UIFont systemFontOfSize:15];
    cipherLabel.textColor = kColors(218, 166, 46, 1);
    cipherLabel.text =@"接头暗号：速降";
    [self.view addSubview:cipherLabel];
    UIButton *exitBtn =[UIButton buttonWithType:UIButtonTypeCustom];
    exitBtn.frame = CGRectMake(15,kScreenHeight-80-64, kScreenWidth-30, 44);
    exitBtn.backgroundColor = kColors(218, 166, 46, 1);
    [exitBtn setTitle:@"退出登录" forState:UIControlStateNormal];
    exitBtn.layer.cornerRadius = 5;
    [exitBtn addTarget:self action:@selector(exitAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:exitBtn];
    
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.dataArray.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == 0) {
        
        return 57;
    }
    return 44;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0 && indexPath.row == 0) {
        personCell = [tableView dequeueReusableCellWithIdentifier:@"MineHomeCell" forIndexPath:indexPath];
        NSData *imageData = [[NSUserDefaults standardUserDefaults]objectForKey:@"headerImage1"];
        personCell.pictureView.image = [UIImage imageWithData:imageData];
        self.ima = personCell.pictureView.image;
        personCell.titleLb.text = self.dataArray[indexPath.row];
        personCell.selectionStyle =UITableViewCellSelectionStyleNone;
          
        return personCell;
    }
    
    
    else {
        static NSString *str = @"PersonCenter";
        cell = [tableView dequeueReusableCellWithIdentifier:str];
        if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:str];
            cell.textLabel.font = [UIFont systemFontOfSize:12];
            cell.selectionStyle = UITableViewCellSelectionStyleNone;
            
            if (indexPath.section==0&&indexPath.row ==1) {
                self.nameLable = [[UILabel alloc]initWithFrame:CGRectMake(230*kWidthScale, 16, 96, 12)];
                self.nameLable.textColor = [UIColor blackColor];
                self.nameLable.font = [UIFont systemFontOfSize:12];
                self.nameLable.text = [[NSUserDefaults standardUserDefaults]objectForKey:@"userName"];
                self.nameLable.textAlignment = NSTextAlignmentCenter;
                 self.name = self.nameLable.text;
                [cell addSubview:self.nameLable];
            }
            if (indexPath.section == 0&&indexPath.row ==2) {
                sexcellLable = [[UILabel alloc]initWithFrame:CGRectMake(230*kWidthScale, 16, 96, 12)];
                sexcellLable.textAlignment = NSTextAlignmentCenter;
                if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"selectIndex"]isEqualToString:@"0"]) {
                    sexcellLable.text =@"  男";
                }
                if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"selectIndex"]isEqualToString:@"1"]) {
                    sexcellLable.text =@"  女";

                }
                if ([[[NSUserDefaults standardUserDefaults]objectForKey:@"selectIndex"]isEqualToString:@"2"]) {
                    sexcellLable.text =@"  保密";
                    
                }

                //sexcellLable.text =[[NSUserDefaults standardUserDefaults]objectForKey:@"sexName"];
                sexcellLable.textColor = [UIColor blackColor];
                sexcellLable.font = [UIFont systemFontOfSize:12];
                [cell addSubview:sexcellLable];
            }
            if (indexPath.section == 0&&indexPath.row == 3) {
                birthDateLable = [[UILabel alloc]initWithFrame:CGRectMake(230*kWidthScale, 16, 96, 12)];
                birthDateLable.textAlignment = NSTextAlignmentCenter;
                birthDateLable .textColor = [UIColor blackColor];
                birthDateLable.text = [[NSUserDefaults standardUserDefaults]objectForKey:@"birthday"];
                birthDateLable.font = [UIFont systemFontOfSize:12];
                [cell addSubview:birthDateLable];
            }
        }
        
        cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
        cell.textLabel.text = self.dataArray[indexPath.row];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        return cell;
    }
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 8;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    //用户头像修改
    if (indexPath.section == 0 &&indexPath.row ==0) {
        
        baseView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        baseView.backgroundColor = [UIColor grayColor];
        baseView.alpha = 0.5;
        [self.view.window addSubview:baseView];
        photoView = [[UIView alloc]initWithFrame:CGRectMake(0, 433*kHeightScale, kScreenWidth, 234*kHeightScale)];
        photoView.backgroundColor = [UIColor whiteColor];
        [self.view.window addSubview:photoView];
        UIButton *photoGraphBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        photoGraphBtn.frame = CGRectMake(22*kWidthScale, 17*kHeightScale, 331*kWidthScale, 44*kHeightScale);
        [photoGraphBtn setTitle:@"拍照" forState:UIControlStateNormal];
        [photoGraphBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        photoGraphBtn.layer.borderWidth = 1;
        photoGraphBtn.layer.cornerRadius = 5;
        photoGraphBtn.layer.borderColor = kColors(197, 204, 207, 1).CGColor;
        [photoGraphBtn addTarget:self action:@selector(photoGraphAct:) forControlEvents:UIControlEventTouchUpInside];
        [photoView addSubview:photoGraphBtn];
        
        
        UIButton *albumBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        albumBtn.frame = CGRectMake(22*kWidthScale, 81*kHeightScale, 331*kWidthScale, 44*kHeightScale);
        [albumBtn setTitle:@"从相册中选择" forState:UIControlStateNormal];
        [albumBtn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [albumBtn addTarget:self action:@selector(albumBtnAct:) forControlEvents:UIControlEventTouchUpInside];
        albumBtn.layer.borderWidth = 1;
        albumBtn.layer.cornerRadius = 5;
        albumBtn.layer.borderColor = kColors(197, 204, 207, 1).CGColor;
        [photoView addSubview:albumBtn];
        
        UIButton *cancelBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        cancelBtn.frame = CGRectMake(22*kWidthScale, 140*kHeightScale, 331*kWidthScale, 44*kHeightScale);
        cancelBtn.layer.cornerRadius = 5;
        [cancelBtn setTitle:@"取消" forState:UIControlStateNormal];
        cancelBtn.backgroundColor = kColors(218, 166, 46, 1);
        [cancelBtn addTarget:self action:@selector(cancelBtnAct:) forControlEvents:UIControlEventTouchUpInside];
        [photoView addSubview:cancelBtn];
    }
    //用户昵称修改
    if (indexPath.section == 0&&indexPath.row == 1) {
        userNameVC = [[UIViewController alloc]init];
        userNameVC.view.backgroundColor = kColors(239, 239, 244, 1);
       
        self.userText = [[PasswordTextField alloc]initWithFrame:CGRectMake(0, 7, kScreenWidth, 44)];
         self.userText.text =[[NSUserDefaults standardUserDefaults]objectForKey:@"userName"];
        self.userText.delegate =self;
        self.userText.placeholder = @"输入3到8个字符";
        self.userText.backgroundColor = [UIColor whiteColor];
        self.userText.font = [UIFont systemFontOfSize:12];
        
        [userNameVC.view addSubview:self.userText];
        userNameVC.navigationItem.title = @"修改昵称";
        [self.navigationController pushViewController:userNameVC animated:YES];
        UIButton *saveBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        saveBtn.frame = CGRectMake(0, 0, 44, 44);
        [saveBtn setTitle:@"保存" forState:UIControlStateNormal];
        [saveBtn addTarget:self action:@selector(saveNameBtnAct:) forControlEvents:UIControlEventTouchUpInside];
        userNameVC.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithCustomView:saveBtn];
    }
    //性别
    if (indexPath.section == 0&&indexPath.row ==2) {
        self.sexTableVC = [[SexTableViewController alloc]init];
        self.sexTableVC.view.backgroundColor =kColors(239, 239, 244, 1);
    
        __weak typeof(UILabel) *sexcell = sexcellLable;
        [self.sexTableVC addBlock:^(NSString *sexStr) {
            sexcell.text= sexStr ;
           [self requestData]; 
        }];
        
        [self.navigationController pushViewController:self.sexTableVC animated:YES];
    }
    //出生日期
    if (indexPath.section ==0&&indexPath.row ==3) {
        baseView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, kScreenHeight)];
        baseView.backgroundColor = [UIColor grayColor];
        baseView.alpha = 0.5;
        [self.view.window addSubview:baseView];
        birthDateView = [[BirthDateView alloc]initWithFrame:CGRectMake(0, 477*kHeightScale, kScreenWidth, 200*kHeightScale)];
        
        NSDateFormatter *currentDateF = [[NSDateFormatter alloc]init];
        [currentDateF setDateFormat:@"yyyy-MM-dd"];
        NSDate *currentDate = [[NSDate alloc]init];
        currentDate = [currentDateF dateFromString:[[NSUserDefaults standardUserDefaults]objectForKey:@"birthday"]];
        if (currentDate !=nil) {
        [birthDateView.dataPicker setDate:currentDate];
        }
        birthDateView.backgroundColor = [UIColor whiteColor];
        [self.view.window addSubview:birthDateView];
        [birthDateView.saveBtn addTarget:self action:@selector(saveBtnAct:) forControlEvents:UIControlEventTouchUpInside];
        [birthDateView.cancelBtn addTarget:self action:@selector(cancelAct:) forControlEvents:UIControlEventTouchUpInside];
         [birthDateView.dataPicker addTarget:self action:@selector(dateChange:) forControlEvents:UIControlEventValueChanged];

    }
    //修改密码
    if (indexPath.section == 0&&indexPath.row == 4)
    {
        PasswordViewController *passwordVC = [[PasswordViewController alloc]init];
        
        [self.navigationController pushViewController:passwordVC animated:YES];
    }
    //收货地址
    if(indexPath.section == 0&&indexPath.row == 5)
    {
        AddressManager *addressVC = [[AddressManager alloc] init];
        [self.navigationController pushViewController:addressVC animated:YES];
    }
    
}



- (UIImagePickerController *)pickerController
{
    if (!_pickerController) {
        _pickerController = [[UIImagePickerController alloc] init];
        
        //设置代理
        _pickerController.delegate = self;
        //设置图片访问类型
        //默认是UIImagePickerControllerSourceTypePhotoLibrary（所有的图片）
       //相册
        //        _pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;//相机
        
        //        _pickerController.cameraDevice = UIImagePickerControllerCameraDeviceRear;//默认的是后置摄像头
        //        _pickerController.cameraDevice = UIImagePickerControllerCameraDeviceFront;//设置为前置摄像头
        
        _pickerController.allowsEditing = YES;
        [self.pickerController.navigationBar setBackgroundImage:[UIImage imageNamed:@"navigationBg"] forBarMetrics:(UIBarMetricsDefault)];
           }
    
    return _pickerController;

}

#pragma mark---------------保存出生日期和姓名----------------
-  (void)dateChange:(id)sender
{
    UIDatePicker *control = (UIDatePicker*)sender;
    
    NSDate *date  = control.date;
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc]init];
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    self.dateAndDay =  [dateFormatter stringFromDate:date];
  
   }

- (void)saveNameBtnAct:(UIButton *)btn
{
    [self.userText resignFirstResponder];
    
      NSString *text = [self.userText.text stringByReplacingOccurrencesOfString:@" " withString:@""];
    
    if ([NSString stringContainsEmoji:text]){
        [Tools showAlert:@"昵称不能含有表情!"];
        return;
    }
    if (text.length<3 || text.length >8) {
        [Tools showAlert:@"昵称必须为3~8个字符!"];
    }
    else{
    self.name = text;
     [self requestData];
      
    }
}

//保存
- (void)saveBtnAct:(UIButton*)btn
{
    if (self.dateAndDay ==nil) {
        [baseView removeFromSuperview];
        [birthDateView removeFromSuperview];
        
    }else{
    birthDateLable.text= self.dateAndDay;
    [self requestData];
    [baseView removeFromSuperview];
    [birthDateView removeFromSuperview];
    }
    
}
//取消
- (void)cancelAct:(UIButton *)btn
{
    [baseView removeFromSuperview];
    [birthDateView removeFromSuperview];
    
}
#pragma mark----------------textdelegate---------------

#pragma mark----------------更换头像-----------------
//拍照
- (void)photoGraphAct:(UIButton *)btn
{
    //判断是否有摄像头
    BOOL isYou = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
    
    if (isYou) {
        NSLog(@"有摄像头");
    }else{
        [Tools showAlert:@"请开启摄像头"];
    }
//    UIImagePickerController *photoPickerController = [[UIImagePickerController alloc]init];
//    photoPickerController.delegate = self;
//    photoPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
//    photoPickerController.allowsEditing = YES;
    _pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
    [baseView removeFromSuperview];
    [photoView removeFromSuperview];
    [self presentViewController:self.pickerController animated:YES completion:nil];

}

//相册
- (void)albumBtnAct:(UIButton *)btn
{
    [self presentViewController:self.pickerController animated:YES completion:nil];
    
    _pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    [baseView removeFromSuperview];
    [photoView removeFromSuperview];
}
//取消
- (void)cancelBtnAct:(UIButton *)btn
{
    [baseView removeFromSuperview];
    [photoView removeFromSuperview];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    
    [self dismissViewControllerAnimated:YES completion:nil];
}

//选择相册（拍照完成）中得相片后执行的方法
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    UIImage *image = nil;
    
    //show
    if (picker.allowsEditing == YES) {
        //获取编辑之后的图片
        image = [info objectForKey:UIImagePickerControllerEditedImage];
    }else {
        //获取原图片
        image = [info objectForKey:UIImagePickerControllerOriginalImage];
        
    }
    
    self.ima = image;
    personCell.pictureView.image =image;
    QNUploadManager *upManager = [[QNUploadManager alloc] init];
    
    NSString *url =[NSString stringWithFormat:@"%@/app.do?cmd=qn_token",kBaseUrl];
    //NSLog(@"%@",url);
    [NetworkHandle getInfoWithUrl:url dictionary:nil success:^(NSDictionary *dictionary) {
        self.token = dictionary[@"data"];
       // NSLog(@"%@",self.token);
        NSString *fileName = [NSString stringWithFormat:@"yonghutouxiang/%@_%@.png",[[NSUserDefaults standardUserDefaults]objectForKey:@"user_id"], [self getDateTimeString]];
        NSData *data = [image resizedAndReturnData];
        [upManager putData:data
                       key:fileName
                     token:self.token
                  complete:^(QNResponseInfo *info, NSString *key, NSDictionary *resp) {
                      self.imageUrl = [NSString stringWithFormat:@"http://7xpm1s.com1.z0.glb.clouddn.com/%@",[resp objectForKey:@"key"]];
;
                      [self requestData];
                  } option:nil];
        
    }];

   
  
    if (picker.sourceType == UIImagePickerControllerSourceTypeCamera) {
        //保存相片到沙盒
        
        NSData *data = UIImagePNGRepresentation(image);
        
        NSString *path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents/student.png"];
        
        BOOL isOK =  [data writeToFile:path atomically:YES];
        if (isOK) {
            NSLog(@"保存沙盒成功：%@",path);
        }
        
        //保存到相册
        UIImageWriteToSavedPhotosAlbum(image,self, @selector(image:didFinishSavingWithError:contextInfo:), nil);
        
    }
    
    //弹出相册
    [self dismissViewControllerAnimated:YES completion:nil];
}
- (void)image:(UIImage *)image didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo
{
    if (error) {
        NSLog(@"保存失败 %@",error);
    }
    NSLog(@"photo 被保存到相册里了");
}
#pragma mark -------------------上传图片名字------------------------
- (NSString *)getDateTimeString
{
    NSDateFormatter *formatter;
    NSString        *dateString;
    
    formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyyMMddHHmmss"];
    
    dateString = [formatter stringFromDate:[NSDate date]];
    
    return dateString;
}

//退出登录
- (void)exitAction
{
    NSString*appDomain = [[NSBundle mainBundle]bundleIdentifier];
    
    [[NSUserDefaults standardUserDefaults]removePersistentDomainForName:appDomain];
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"isFirst"];
    AppDelegate *app = (AppDelegate *)[UIApplication sharedApplication].delegate;
    [app setRootVC];
}


/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
